<?php

class news extends bhCommon {

    public function __construct()
    {
        parent::__construct();
    }


    public function index()
    {
        $page_size = 10;
        $p = $this->get('p', 1);
        $limit = ($p - 1) * $page_size;
        $news = p_getall('new', array('state' => 1), array(),'', array('sort desc'), "{$limit}, {$page_size}");

        foreach ($news as & $v) {
            $v['cover_image'] = getImage($v['cover_image']);
            $v['author_image'] = getImage($v['author_image']);
            $v['created'] = date('m月d日', $v['created']);
        }

        $config = array(
            'ad_type' => getConfig('ad_type', 1),
            'grid_ad' => getConfig('grid_ad'),
        );

        $data = array(
            'news' => $news,
            'config' => $config
        );
        $this->json($data);
    }



    public function details()
    {
        $id = $this->get('id');

        $details = p_get('new', array('id' => $id));
        $details['browse']++;
        p_update('new', array('browse' => $details['browse']), array('id' => $details['id']));
        $details['time'] = formatTime($details['created']);

        $config = array(
            'ad_type' => getConfig('ad_type', 1),
            'grid_ad' => getConfig('grid_ad'),
        );
        $config['ad_show_type'] = $this->rising->get_ad_type($config['ad_type']);
        $data = array(
            'news' => $details,
            'config' => $config
        );
        $this->json($data);
    }






}